﻿#pragma once
#include "includeBase.h"

#include <QtPropertyBrowser/QtDoublePropertyManager>
#include <QtPropertyBrowser/QtDoubleSpinBoxFactory>
#include <QtPropertyBrowser/QtTreePropertyBrowser>
#include <QtPropertyBrowser/QtVariantPropertyManager>

/// <summary>
/// PropertyManager
/// </summary>
class PropertyProvider : public QObject
{
    Q_OBJECT

public:
    PropertyProvider();

public:
    virtual void initEditor(QtTreePropertyBrowser* editor);
    virtual void valueChanged(QtProperty*, double);
    virtual void valueChanged(QtProperty*, QString);
    virtual void valueChanged(QtProperty*, int);
    virtual void valueChanged(QtProperty*, bool);
    virtual void valueChanged(QtProperty*, const QColor&);
    virtual void close();

protected:
    void addProperty(QtProperty* property, const QString& id);
    void addSubProperty(
        QtProperty* parent,
        QtProperty* property,
        const QString& id
    );

private slots:
    void onValueChanged(QtProperty*, double);
    void onValueChanged(QtProperty*, QString);
    void onValueChanged(QtProperty*, int);
    void onValueChanged(QtProperty*, bool);
    void onValueChanged(QtProperty*, const QColor&);

protected:
    QtTreePropertyBrowser* editor_ = nullptr;

    // 属性栏管理
    QtDoublePropertyManager* doubleManager;
    QtStringPropertyManager* stringManager;
    QtIntPropertyManager* intManager;
    QtEnumPropertyManager* enumManager;
    QtBoolPropertyManager* boolManager;
    QtVariantPropertyManager* variantManager;
    QtFilePathPropertyManager* fileManager;
    QtColorPropertyManager* colorManager;
    QtPushButtonPropertyManager* pushButtonManager;

    // 属性栏工厂
    QtDoubleSpinBoxFactory* doubleSpinBoxFactory;
    QtLineEditFactory* lineEditFactory;
    QtSpinBoxFactory* spinBoxFactory;
    QtEnumEditorFactory* enumFactory;
    QtCheckBoxFactory* checkBoxFactory;
    QtVariantEditorFactory* variantFactory;
    QtFilePathEditorFactory* fileFactory;
    QtColorEditorFactory* colorFactory;
    QtPushButtonFactory* pushButtonFactory;

    // 属性栏映射
    QMap<QtProperty*, QString> propertyToId;
    QMap<QString, QtProperty*> idToProperty;
};
